
package TransportesMarroquin;

import com.mysql.jdbc.Connection;

import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import java.awt.event.KeyEvent;
import java.io.FileNotFoundException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ButtonGroup;
import javax.swing.JOptionPane;


public class NuevoViajePiloto extends javax.swing.JFrame {

 
static boolean nuevo = false;
boolean error = false;
int resultado;
int enviarcod;
int ncod;
static int codigovehiculo;
static String tipo= "Camion";
 ButtonGroup bc;
 String consulta = "select idcamion, placa, marca from Camion"; ;

static NuevoViajeDatos va;
    public NuevoViajePiloto(int n) {
        initComponents();
        enviarcod= n;
        bc = new ButtonGroup();
        bc.add(bcamion);
        bc.add(bcabezal);
        
    }

    private NuevoViajePiloto() {
    }

    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        ct = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        cnom = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        clic = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        cape = new javax.swing.JTextField();
        cd = new javax.swing.JTextField();
        ct1 = new javax.swing.JLabel();
        cdv = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        bcamion = new javax.swing.JRadioButton();
        bcabezal = new javax.swing.JRadioButton();
        jButton6 = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        cpla = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        ct.setText("P I L O T O ");
        ct.setName("ct"); // NOI18N

        jPanel1.setBackground(new java.awt.Color(143, 0, 0));
        jPanel1.setName("jPanel1"); // NOI18N

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
        jLabel3.setText("Nuevo Viaje ");
        jLabel3.setName("jLabel3"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addContainerGap(267, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/regresar.png"))); // NOI18N
        jButton1.setText(" Regresar ");
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/siguiente.png"))); // NOI18N
        jButton4.setText("Siguiente");
        jButton4.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
        jButton4.setName("jButton4"); // NOI18N
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/1316234747_search_b.png"))); // NOI18N
        jButton5.setText("Buscar");
        jButton5.setName("jButton5"); // NOI18N
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        cnom.setEnabled(false);
        cnom.setName("cnom"); // NOI18N
        cnom.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cnomActionPerformed(evt);
            }
        });
        cnom.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                cnomKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                cnomKeyTyped(evt);
            }
        });

        jLabel10.setText("Apellido ");
        jLabel10.setName("jLabel10"); // NOI18N

        jLabel1.setText("C o d i g o ");
        jLabel1.setName("jLabel1"); // NOI18N

        clic.setEnabled(false);
        clic.setName("clic"); // NOI18N
        clic.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clicActionPerformed(evt);
            }
        });

        jLabel2.setText("N o m b r e");
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel4.setText("Licencia");
        jLabel4.setName("jLabel4"); // NOI18N

        cape.setEnabled(false);
        cape.setName("cape"); // NOI18N
        cape.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                capeKeyTyped(evt);
            }
        });

        cd.setEnabled(false);
        cd.setName("cd"); // NOI18N
        cd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cdActionPerformed(evt);
            }
        });

        ct1.setText("V E H I C U L O ");
        ct1.setName("ct1"); // NOI18N

        cdv.setEnabled(false);
        cdv.setName("cdv"); // NOI18N
        cdv.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cdvActionPerformed(evt);
            }
        });

        jLabel5.setText("C o d i g o ");
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setText("Tipo Vehículo");
        jLabel6.setName("jLabel6"); // NOI18N

        bcamion.setSelected(true);
        bcamion.setText("Camion ");
        bcamion.setName("bcamion"); // NOI18N
        bcamion.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                bcamionMouseClicked(evt);
            }
        });

        bcabezal.setText("Cabezal");
        bcabezal.setName("bcabezal"); // NOI18N
        bcabezal.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                bcabezalMouseClicked(evt);
            }
        });

        jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/1316234747_search_b.png"))); // NOI18N
        jButton6.setText("Buscar");
        jButton6.setName("jButton6"); // NOI18N
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jLabel7.setText("Placa");
        jLabel7.setName("jLabel7"); // NOI18N

        cpla.setEnabled(false);
        cpla.setName("cpla"); // NOI18N
        cpla.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cplaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 145, Short.MAX_VALUE)
                .addComponent(jButton4)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(18, 18, 18)
                                .addComponent(cd, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel10)
                                    .addComponent(jLabel4))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(clic)
                                    .addComponent(cnom)
                                    .addComponent(cape, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE)
                                    .addComponent(cpla, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton5))))
                    .addComponent(ct))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(jLabel7)
                .addContainerGap(348, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jLabel6))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jLabel5))
                            .addComponent(ct1))))
                .addGap(13, 13, 13)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cdv, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(bcamion)
                        .addGap(17, 17, 17)
                        .addComponent(bcabezal)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 55, Short.MAX_VALUE)
                        .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton5, jButton6});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cape, clic, cnom, cpla});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton1, jButton4});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(ct)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(cd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel10)
                        .addComponent(cape, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton5))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(cnom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(32, 32, 32)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(clic, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(11, 11, 11)
                .addComponent(ct1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(cdv, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(bcabezal)
                    .addComponent(jButton6)
                    .addComponent(bcamion))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 21, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(cpla, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jButton5, jButton6});

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jButton1, jButton4});

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
      Viaje.va.show();
      
      dispose();
      
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
     error = false;
// despues qee verifique que los datos esten bien los guardare en nuevo cliente. 
                    
    if(nuevo){
       NuevoPiloto();
                    }  
  
    if(!nuevo){
        try {
                        Insertar();
                    } catch (FileNotFoundException ex) {
                        Logger.getLogger(NuevoCabezal.class.getName()).log(Level.SEVERE, null, ex);
                    }
    }
                    
                    
                 if (!error){
                    NuevoViajeCliente.va.dispose(); 
                    va = new NuevoViajeDatos(enviarcod,codigovehiculo,tipo); // el codigo del camion qee voy a enviar a llantasfurgon
                    va.setVisible(true);
                    
                 }  
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
       AyudaPiloto ap = new AyudaPiloto();
       ap.setVisible(true);
       ap.setBounds(this.getSize().width,0,va.getSize().width,this.getSize().height);
    }//GEN-LAST:event_jButton5ActionPerformed

    private void cnomActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cnomActionPerformed
        
}//GEN-LAST:event_cnomActionPerformed

    private void cnomKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cnomKeyReleased
        
}//GEN-LAST:event_cnomKeyReleased

    private void clicActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clicActionPerformed
        
}//GEN-LAST:event_clicActionPerformed

    private void cdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cdActionPerformed
        
}//GEN-LAST:event_cdActionPerformed

    private void cdvActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cdvActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cdvActionPerformed

    private void bcabezalMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_bcabezalMouseClicked
if(bcabezal.isSelected())
{
    tipo = "Cabezal";
    consulta = "select idcabezal, placa, marca from Cabezal";
}
    }//GEN-LAST:event_bcabezalMouseClicked

    private void bcamionMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_bcamionMouseClicked
       if(bcamion.isSelected())
{
    tipo = "Camion";
    consulta = "select idcamion, placa, marca from Camion";
}
    }//GEN-LAST:event_bcamionMouseClicked

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
       AyudaVehiculo av = new AyudaVehiculo(consulta, tipo);
       av.setVisible(true);
       av.setBounds(this.getSize().width,0,av.getSize().width,this.getSize().height); 
    }//GEN-LAST:event_jButton6ActionPerformed

    private void cplaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cplaActionPerformed
      
    }//GEN-LAST:event_cplaActionPerformed

    private void cnomKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cnomKeyTyped
          char c = evt.getKeyChar();
      if (!(Character.isLetter(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE) || ((c== KeyEvent.VK_SPACE)))) {
            getToolkit().beep();
            evt.consume();
}
    }//GEN-LAST:event_cnomKeyTyped

    private void capeKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_capeKeyTyped
           char c = evt.getKeyChar();
      if (!(Character.isLetter(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE) || ((c== KeyEvent.VK_SPACE)))) {
            getToolkit().beep();
            evt.consume();
}
    }//GEN-LAST:event_capeKeyTyped
 public void NuevoPiloto (){
        try {
            
            
            MysqlDataSource dataSource = new MysqlDataSource();
            dataSource.setUser("root");
            dataSource.setPassword("");
            dataSource.setDatabaseName("practicasp8");
            dataSource.setServerName("localhost");
             // coneccion
            Connection conexion = (Connection) dataSource.getConnection();
            ResultSet rs;
            PreparedStatement ps = null;
            ps = (PreparedStatement) conexion.prepareStatement("insert into piloto (idpiloto,nombre,apellido,licencia) values (?,?,?,?)",PreparedStatement.RETURN_GENERATED_KEYS);

                try {
                     ps.setInt(1,Integer.parseInt(cd.getText()));
                }catch(Exception e){
                       JOptionPane.showMessageDialog(rootPane, "Dato erroneo en el id del piloto, no es un dato númerico");

               } // fin del catch
            ps.setString(2,cnom.getText()); 
            ps.setString(3,cape.getText());   
            ps.setString(4,cape.getText());
     
             resultado = ps.executeUpdate();
             
             rs = ps.getGeneratedKeys();
            while (rs.next()) {
                ncod = rs.getInt(1);
                
                }
              // lleno el codigo 
                cd.setText(""+ncod);
                nuevo = false;  // ahora si ya no es un nuevo 
               conexion.close(); // cierro la conexion
               ps.close();

             }catch(SQLException e){
                  nuevo = true; // error 
            System.out.println("EXCEPCION EN Base de Datos:"+e.toString());
           } // fin del catch
    }
  public void Insertar() throws FileNotFoundException{
     
    try {
           

            MysqlDataSource dataSource = new MysqlDataSource();
            dataSource.setUser("root");
            dataSource.setPassword("");
            dataSource.setDatabaseName("practicasp8");
            dataSource.setServerName("localhost");
            ResultSet rs;
            // coneccion
            Connection conexion = (Connection) dataSource.getConnection();

            PreparedStatement ps = null;
            ps = (PreparedStatement) conexion.prepareStatement("UPDATE viaje set id_piloto=?, nombre_piloto=?, apellido_piloto=?, licencia_piloto=?,codigo_vehiculo=?,tipo_vehiculo=?,placa_vehiculo=? where idviaje = ?");
// PRIMER CAMPO 
            try{
            ps.setInt(1,Integer.parseInt(cd.getText())); 
           
        
         }catch (Exception e) {
             JOptionPane.showMessageDialog(rootPane, "Dato erroneo en el codigo del piloto no es un dato númerico.");
         }
          
 // SEGUNDO CAMPO 
            ps.setString(2,cnom.getText());
            
// TERCER CAMPO 
            ps.setString(3,cape.getText());
            
// CUARTO CAMPO 
            ps.setString(4,clic.getText());
            
            
// QUINTO CAMPO 
        
              try{
           
           codigovehiculo=Integer.parseInt(cdv.getText());
        
         }catch (Exception e) {
             JOptionPane.showMessageDialog(rootPane, "Dato erroneo en el codigo del vehiculo no es un dato númerico.");
         }
           ps.setInt(5,codigovehiculo); 
// SEXTO CAMPO 
           ps.setString(6,tipo);   
// SEPTIMO CAMPO 
           ps.setString(7,cpla.getText());
// OCTAVO CAMPO 
            try{
            ps.setInt(8,enviarcod); 
            
        
         }catch (Exception e) {
             JOptionPane.showMessageDialog(rootPane, "Dato erroneo en el codigo del viaje");
         }
              
      
         
             resultado = ps.executeUpdate();


               conexion.close(); // cierro la conexion
               ps.close();

             }catch(SQLException e){
             JOptionPane.showMessageDialog(rootPane,"Error en Programa:"+e);
         
           
            error = true;
            
           } // fin del catch
}  
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new NuevoViajePiloto().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton bcabezal;
    private javax.swing.JRadioButton bcamion;
    public static javax.swing.JTextField cape;
    public static javax.swing.JTextField cd;
    public static javax.swing.JTextField cdv;
    public static javax.swing.JTextField clic;
    public static javax.swing.JTextField cnom;
    public static javax.swing.JTextField cpla;
    private javax.swing.JLabel ct;
    private javax.swing.JLabel ct1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
}
